package cn.itheima.service.impl;

import cn.itheima.mapper.UserMapper;
import cn.itheima.pojo.User;
import cn.itheima.service.UserService;
import cn.itheima.utils.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 董代恒
 * @version 1.0
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 根据用户名查看用户是否存在,不存在就注册
     * @param username
     * @return
     */
    @Override
    public User findByUsername(String username) {
        User u = userMapper.findByUsername(username);
        return u;
    }

    /**
     * 注册
     * @param username
     * @param password
     */
    @Override
    public void register(String username, String password) {
        String md5Password = Md5Util.getMD5String(password);
        userMapper.add(username,md5Password);
    }
}
